package dw.common;

import java.io.Serializable;
import java.util.List;

/**
 * A generic DAO interface definition.  This interface should be extended
 * even if the new interface will add no additional functions.
 * 
 * @param <T> The class of the pojo being persisted.
 * @param <I> the class of the pojo's id property.
 */
public interface GenericDao<T, I extends Serializable> {
  /**
   * Get the object with the id specified.
   * 
   * @param id the id of the instance to retrieve.
   * 
   * @return the instance with the given id.
   */
  T findById(I id);

  /**
   * Get all instances that match the properties that are set in the given 
   * object using a standard Query by Example method.
   *  
   * @param t the example bean
   * 
   * @return a list of beans that match the example.
   */
  List<T> findByExample(T t);

  /**
   * Get all instances of this bean that have been persisted.
   * 
   * @return a list of all instances.
   */
  List<T> findAll();

  /**
   * Persist the given bean.
   * 
   * @param t the bean to persist.
   */
  void saveOrUpdate(T t);

  /**
   * Remove the bean with the given id.
   *
   * @param id the id of the bean to remove.
   */
  void delete(I id);

  /**
   * Remove the bean passed.  same as remove(t.<idProoertyGetter>())
   * 
   * @param t the object to remove.
   */
  void delete(T t);

  /**
   * Get the object(s) of the id's specified.
   * 
   * @param collectionOfIds are the id's of the instance to retrieve.
   * 
   * @return the instance(s) of the given id's.
   */
  List<T> findByIds(String propertyNameOfId, List<I> collectionOfIds);
}
